﻿using Customer.API.Applcation.Command.VendorCommand;
using Customer.Infrstructre.VendorManager;
using MediatR;

namespace Customer.API.Applcation.CommandHandlers.VendorCommandHandler
{
    /// <summary>
    /// 删除供应商
    /// </summary>
    public class DelVendorCommandHandler:IRequestHandler<DelVendorCommand,int>
    {
        private readonly IVendorRepository _vendorRep;
        public DelVendorCommandHandler(IVendorRepository _vendorRep)
        {
            this._vendorRep = _vendorRep;
        }

        public async Task<int> Handle(DelVendorCommand request, CancellationToken cancellationToken)
        {
            foreach (var item in request.VendorId)
            {
                var list = await _vendorRep.GetModelAsync(item);
                list.IsDel = true;
                await _vendorRep.Update(list);
            }
            return 1;
        }
    }
}
